#!/usr/bin/env python
# -*- coding:utf-8 -*-

import re

print('匹配至少一个数字' + ' -----------------------------------------------------------------------------------------------------------------------')
# match是从字符串开头开始找的,返回第一个符合规则的字符串，只匹配一次
pattern = re.compile(r'\d+')
m = pattern.match('dkfjdkfk333')
n = pattern.match('aaaaa12345bbbbb12345', 5, 20)
print(m)  # None
print(n.group())  # 12345


print('复杂' + ' -----------------------------------------------------------------------------------------------------------------------')
# re.I 忽略大小写
# re.S 忽略全文匹配
pattern = re.compile(r'([a-z]+) ([a-z]+)', re.I)  # 中间有一个空格
m = pattern.match('Hello world hello Python')
print(m.group(0))  # Hello world
print(m.group(1))  # Hello
print(m.group(2))  # world
print(m.span(1))  # (0, 5)
print(m.span(2))  # (6, 11)

